void gotoxy(int x, int y);
void Play();
void HuongDan();
void Thoat();
void Logo();
void Menu();
//Ham clrscr
void clrscr(void)
{
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE hConsoleOut;
COORD Home = {0,0};
DWORD dummy;

hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);

FillConsoleOutputCharacter(hConsoleOut,' ',csbiInfo.dwSize.X *
csbiInfo.dwSize.Y,Home,&dummy);
csbiInfo.dwCursorPosition.X = 0;
csbiInfo.dwCursorPosition.Y = 0;
SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);
}
//Ham di chuyen menu
int DiChuyen(){
	unsigned char tl;
	int dem=0;
	gotoxy(17,14);
	printf("%c",26) ;
	while(1){
		if (kbhit())
			tl = getch();
		if(tl==224)
			tl = getch();
		if (tl==13) return dem;
		if (tl==72){
			tl=0;
			gotoxy(17,14+dem);
			printf(" ");
			if(dem==0) dem = 3;
				else dem--;
			gotoxy(17,14+dem);
			printf("%c",26);
		}
		if (tl==80){
			tl=0;
			gotoxy(17,14+dem);
			printf(" ");
			if(dem==3) dem = 0;
				else dem++;
			gotoxy(17,14+dem);
			printf("%c",26);
		} 
	}
	fflush(stdin);
}
//Ham Gotoxy
void gotoxy(int x, int y)
{
  static HANDLE h = NULL;  
  if(!h)
    h = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD c = { x, y };  
  SetConsoleCursorPosition(h,c);
}

//Ham tao khung: 30x20
void Khung(){
	printf("\t  Snake!!! Press Enter to PAUSE\n");
	int i,j;
	for (i=1;i<=20;i++){
		for(j=1;j<=30;j++)
			if (i==1||j==1||i==20||j==30) printf("x"); else printf(" ");
		printf("\n");
		}
}
//Ham hien thi: Input: NULL
void HienThi(){
	int i;
	gotoxy(Ran.A[0].x,Ran.A[0].y);
	printf("O");
	for(i=1;i<Ran.l;i++){
		gotoxy(Ran.A[i].x,Ran.A[i].y);
		printf("o");
		//Sleep(200);
		//gotoxy(34,1);
	}
	gotoxy(Tam.x,Tam.y);
	printf(" ");
}

void HienThi2(){
	int i;
	gotoxy(Ran2.A[0].x,Ran2.A[0].y);
	printf("@");
	for(i=1;i<Ran2.l;i++){
		gotoxy(Ran2.A[i].x,Ran2.A[i].y);
		printf("*");
	}
	gotoxy(Tam2.x,Tam2.y);
	printf(" ");
}

//Ham Khoi tao ran: l = 3
void KhoiTao(){
	Ran.l=5;
	Ran.A[0].x = 15;
	Ran.A[0].y = 10;
	Ran.A[1].x = 14;
	Ran.A[1].y = 10;
	Ran.A[2].x = 13;
	Ran.A[2].y = 10;
	Ran.A[3].x = 12;
	Ran.A[3].y = 10;
	Ran.A[4].x = 11;
	Ran.A[4].y = 10;
	Diem=0;
	k=1;k2=0;
	BanPhim=77;temp=77;
	Tam.x=34;Tam.y=22;
	if(Mod==2)
	{
	Ran2.l=5;
	Ran2.A[0].x = 10;
	Ran2.A[0].y = 6;
	Ran2.A[1].x = 9;
	Ran2.A[1].y = 6;
	Ran2.A[2].x = 8;
	Ran2.A[2].y = 6;
	Ran2.A[3].x = 7;
	Ran2.A[3].y = 6;
	Ran2.A[4].x = 6;
	Ran2.A[4].y = 6;
	k2=1;
	BanPhim2=100;temp2=100;
	Tam2.x=35;Tam2.y=22;
	}
}
//Hien thi Qua
void HTQua(){
	gotoxy(Qua.x,Qua.y);
	printf("%c",1);
}

